package com.study;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.subject.Subject;

/**
 * @author MI
 * @ClassName TestCustomerRealmAuthenticator.java
 * @createTime 2021年08月20日 12:23:00
 */
public class TestCustomerRealmAuthenticator {
    public static void main(String[] args) {
        //1 创建安全管理器对象
        DefaultSecurityManager securityManager = new DefaultSecurityManager();

        //2 给安全管理器设置 自定义 realm
        securityManager.setRealm(new CustomerRealm());
        // 安全工具
        SecurityUtils.setSecurityManager(securityManager);
        //从安全工具里获取 subject 主体
        Subject subject = SecurityUtils.getSubject();
        //创建token
        UsernamePasswordToken token = new UsernamePasswordToken("xiaochen", "123");

        subject.login(token);
    }
}
